const { defineConfig } = require('@vue/cli-service')
// const AutoImport = require('unplugin-auto-import/webpack') 
const port = process.env.port || process.env.npm_config_port || 80 // 端口
module.exports = defineConfig({
	//设置为空打包后不分更目录还是多级目录
	publicPath:'',
	//build编译后存放静态文件的目录
	//assetsDir: "static",

	// build编译后不生成资源MAP文件
	productionSourceMap: false,

	//开发服务,build后的生产模式还需nginx代理
	devServer: {
    allowedHosts: 'all',
		
		open: true, //运行后自动打开浏览器
		port: port, //挂载端口
		proxy: {
			[process.env.VUE_APP_BASE_API]: {
        target: `https://b5a0148.r12.vip.cpolar.cn/`,
        changeOrigin: true,
        pathRewrite: {
          ['^' + process.env.VUE_APP_BASE_API]: ''
        }
      }
		},
		client: {
			overlay: false,
		},
	},
	lintOnSave: false,

	chainWebpack: config => {
		// 移除 prefetch 插件
		config.plugins.delete('preload');
		config.plugins.delete('prefetch');
		config.resolve.alias.set('vue-i18n', 'vue-i18n/dist/vue-i18n.cjs.js');
		config.when(process.env.NODE_ENV !== 'development', config => {
			// const CompressionWebpackPlugin = require('compression-webpack-plugin')
			// config.plugin('CompressionPlugin').use(
			// 	new CompressionWebpackPlugin({
			// 		test: /\.(js|css)$/,
			// 		threshold: 10240, // 超过10kb的文件就压缩
			// 		deleteOriginalAssets: true, // 不删除源文件
			// 		minRatio: 0.8
			// 	})
			// )
		})
	},

	configureWebpack: {
		plugins: [
      require('unplugin-auto-import/webpack').default({
				imports: [
					// 需要自动导入的插件，自定义导入的API
					'vue',
					'vue-router',
					'vuex'
				]
			}),
    ],
		//性能提示
		performance: {
			hints: false
		},
		optimization: {
			splitChunks: {
				chunks: "all",
				automaticNameDelimiter: '~',
				name: "scuiChunks",
				cacheGroups: {
					//第三方库抽离
					vendor: {
						name: "modules",
						test: /[\\/]node_modules[\\/]/,
						priority: -10
					},
					elicons: {
						name: "elicons",
						test: /[\\/]node_modules[\\/]@element-plus[\\/]icons-vue[\\/]/
					},
					tinymce: {
						name: "tinymce",
						test: /[\\/]node_modules[\\/]tinymce[\\/]/
					},
					echarts: {
						name: "echarts",
						test: /[\\/]node_modules[\\/]echarts[\\/]/
					},
					xgplayer: {
						name: "xgplayer",
						test: /[\\/]node_modules[\\/]xgplayer.*[\\/]/
					},
					codemirror: {
						name: "codemirror",
						test: /[\\/]node_modules[\\/]codemirror[\\/]/
					}
				}
			}
		}
	}
})
